package ro.msg.quiz.controller;

import ro.msg.quiz.Model.IQuizModel;
import ro.msg.quiz.Model.QuizModel;
import ro.msg.quiz.repository.Question;
import ro.msg.quiz.repository.Quiz;

/**
 * @author Blaj controller for the no gui view
 * 
 */
public class QuizController {
	private IQuizModel mdl;

	/**
	 * @param mdl
	 *            constructor takeing a model as parameter
	 */
	public QuizController(IQuizModel mdl) {
		this.setModel(mdl);
	}

	/**
	 * Constructor without parameter
	 * 
	 */
	QuizController() {
		this.setModel(new QuizModel());
	}

	/**
	 * Return the model in the controller
	 * 
	 * @return IQuizModel
	 */
	public IQuizModel getModel() {
		return mdl;
	}

	/**
	 * Sets the model for the controller
	 * 
	 * @param mdl
	 */
	public void setModel(IQuizModel mdl) {
		this.mdl = mdl;
	}

	/**
	 * add a question to the repository
	 * 
	 * @param q
	 */
	public void addQuestion(Question q) {
		this.mdl.addQuestion(q);
	}

	/**
	 * Remove a question from the repository
	 * 
	 * @param ques
	 * @return true or false
	 */
	public boolean removeQuestion(int ques) {
		return this.mdl.removeQuestion(ques);
	}

	/**
	 * Add quiz to the repository
	 * 
	 * @param v
	 *            of type Quiz
	 */
	public void addQuiz(Quiz v) {
		this.mdl.addQuiz(v);
	}

	/**
	 * Removes a quiz from the repository based on the id
	 * 
	 * @param a
	 */
	public void removeQuiz(int a) {
		this.mdl.removeQuiz(a);
	}

	/**
	 * Adds a question to a quiz inside the map of the model
	 * 
	 * @param quiz
	 * @param ques
	 * @return true if succeded false instead
	 */
	public boolean addQuestionToQuiz(Integer quiz, Integer ques) {
		return this.mdl.addQuestionToQuiz(quiz, ques);
	}

	/**
	 * Removes a question from a quiz inside the map of the model
	 * 
	 * @param quiz
	 * @param ques
	 * @return true if succeded false instead
	 */
	public boolean removeQuestionFromQuiz(Integer quiz, Integer ques) {
		return this.mdl.removeQuestionFromQuiz(quiz, ques);
	}

	/**
	 * Prints all questions
	 * 
	 */
	public void printAllQuestions() {
		for (Question temp : this.mdl.getQuestionRepo().getQuestionsList()) {
			System.out.println(temp.toString());
		}
	}

	/**
	 * Prints all quizes
	 */
	public void printAllQuizes() {
		for (Quiz temp : this.mdl.getQuizRepo().getQuizes()) {
			System.out.println(temp.toString());
		}
	}

	/**
	 * Prints the map
	 */
	public void printMap() {
		this.mdl.printMap();
	}

}
